package com.siyu.tickets.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.siyu.common.page.Pagination;
import com.siyu.common.page.SimplePage;
import com.siyu.common.web.CookieUtils;
import com.siyu.tickets.entity.Element;
import com.siyu.tickets.entity.Product;
import com.siyu.tickets.manager.ElementMng;
import com.siyu.tickets.manager.ProductMng;

/**
 * 商品查询下单相关
 * 
 * @since 2013-7-15
 * @version 0.1
 * @author cuigx
 */
@Controller
public class GoodsAct {

	private static final Logger log = LoggerFactory.getLogger(GoodsAct.class);

	@RequestMapping("/goods/eticket")
	public String eticket(String key, Integer typeId, Integer groupId, Integer cityId, Integer pageNo,
			HttpServletRequest request, ModelMap model) {
		Pagination pagination = manager.getPage(key, null, null, typeId, groupId, cityId, null, true,
				SimplePage.cpn(pageNo), CookieUtils.DEFAULT_SIZE);

		List<Element> cityList = elementManager.findListByType(Element.ELE_TYPE_CITY);
		model.addAttribute("cityList", cityList);
		List<Element> groupList = elementManager.findListByType(Element.ELE_TYPE_GROUP);
		model.addAttribute("groupList", groupList);

		model.addAttribute("key", key);
		model.addAttribute("typeId", typeId);
		model.addAttribute("groupId", groupId);
		model.addAttribute("cityId", cityId);
		model.addAttribute("pagination", pagination);
		model.addAttribute("pageNo", pagination.getPageNo());

		return "product/eticket";
	}

	@RequestMapping("/goods/detail/{id}")
	public String eticket(@PathVariable(value = "id") Integer id, HttpServletRequest request, ModelMap model) {
		Product product = manager.findById(id);
		model.addAttribute("product", product);
		return "product/detail";
	}

	@RequestMapping("/goods/buy/{id}")
	public String buy(@PathVariable(value = "id") Integer id, HttpServletRequest request, ModelMap model) {
		Product product = manager.findById(id);
		model.addAttribute("product", product);
		return "product/buy";
	}

	@Autowired
	private ProductMng manager;

	@Autowired
	private ElementMng elementManager;
}
